//
//  ViewController.m
//  28-UIViewAnimation
//
//  Created by 王道林 on 16/8/22.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIView *animationView1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
// 红色的
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    _animationView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationView];
// 蓝色的
    self.animationView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
    _animationView1.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_animationView1];

    
#if 1
    // 1. UIView Animation
    // 开始动画设置
    // 参数1 : 动画标识
    // 参数2 : 上下文
    [UIView beginAnimations:nil context:NULL];
    // 设置动画曲线, 如何进行动画运动
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:3];
    // 4> 延时时间
    [UIView setAnimationDelay:2];
//    [UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:10]];
    // 7 >
//    [UIView setAnimationRepeatCount:2.5];
    // 设置往返动画,  一个来回算一次
//    [UIView setAnimationRepeatAutoreverses:YES];
    //  忽略动画过程
    [UIView setAnimationsEnabled:YES];
    // 设置动画
    _animationView.wdl_x = 100;
    _animationView1.wdl_y = 500;
    
    // 5>
    // 签订代理
    [UIView setAnimationDelegate:self];
    //  将要开始
    [UIView setAnimationWillStartSelector:@selector(animationWillStart: context:)];
    //  已经结束
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    // 7 >
//    [UIView setAnimationRepeatCount:2.5];
    
    // 结束动画设置, 执行该动画
    [UIView commitAnimations];
    
#endif
    // 2. UIViewAnimationBlock
    
    //1>
    [UIView animateWithDuration:5 animations:^{
        _animationView.wdl_width = 300;
    }];
    
    //2>
    [UIView animateWithDuration:3 animations:^{
        _animationView.wdl_height = 200;
    } completion:^(BOOL finished) {
        NSLog(@"动画完成后,需要执行的操作");
    }];
    
    // 3>
    [UIView animateWithDuration:2 delay:3 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
        _animationView1.wdl_width = 200;
    } completion:^(BOOL finished) {
        
    }];
    
}




-(void)animationWillStart:(NSString *)animationID context:(void *)context
{
    NSLog(@"开始");
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    NSLog(@"结束");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
